<!-- 补考课程成绩单打印-->
<template>
  <div class="assessment-container" style="width:100%">
    <div class="search-container" style="marign:0;padding-left: 0;">
      <div class="search-container-left">
        <div class="search-container-item">
          <span v-if="type === 'one'">补考学期：</span>
          <el-select
            v-if="type === 'one'"
            v-model="xq"
            style="width: 90px"
            size="mini"
            placeholder="请选择"
            clearable
          >
          <!-- @clear="scoreBuAll" -->
            <el-option
              v-for="item in xqList"
              :key="item.value"
              :label="item.xqmc"
              :value="item.xqmc"
            >
            </el-option>
          </el-select>
          <span v-if="type === 'two'">第二次补考学期：</span>
          <el-select
            v-if="type === 'two'"
            v-model="onemorexueqi"
            style="width: 90px"
            size="mini"
            placeholder="请选择"
            clearable
          >
          <!-- @clear="scoreBuAll" -->
            <el-option
              v-for="item in xqList"
              :key="item.value"
              :label="item.xqmc"
              :value="item.xqmc"
            >
            </el-option>
          </el-select>
        </div>
        <div class="search-container-item">
          <span>课程负责单位：</span>
          <el-select
            v-model="xb"
            style="width: 120px;margin-right:5px"
            size="mini"
            placeholder="请选择"
            @change="handleXb"
            clearable
          >
            <el-option
             style="margin-right:5px"
              v-for="(item,index) in xbList"
              :key="index"
              :label="item.deptName"
              :value="item.deptName"
            >
            </el-option>
          </el-select>
          <el-select
            v-model="gClass"
            style="width: 120px"
            size="mini"
            placeholder="请选择"
            @change="handleClass"
            clearable
          >
            <el-option
              v-for="(item,index) in gClassList"
              :key="index"
              :label="item.deptName ? item.deptName : item.value"
              :value="item.deptName ? item.deptName : item.value"
            >
            </el-option>
          </el-select>
        </div>
         <div class="search-container-item">
          <span>培养层次：</span>
          <el-select
              v-model="eduLevel"
              size="mini"
              style="width: 120px"
              placeholder="请选择"
              clearable
            >
            <el-option
              v-for="item in levelList"
              :key="item.dictKey"
              :label="item.dictValue"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
        <div class="search-container-item">
          <span>课程名称：</span>
          <el-input
            style="width: 152px"
            size="mini"
            placeholder="请输入内容"
            v-model="coursename"
            clearable
          ></el-input>
        </div>
        <div class="search-button" @click="searchClick" style="margin:2px 0 0 0">
          <img src="../../../assets/assessment/icon-search.png" alt="" />
          <span>查询</span>
        </div>
        <div class="search-container-right" style="margin:2px 0 0 0" v-if="type == 'one'">     
          <div class="export-button" style="margin-left:15px;margin-top:0" >
            <img src="../../../assets/assessment/icon-export.png" alt="" />
            <span @click="clickAllExcel">批量打印补考成绩单</span>
          </div>
        </div>
        <div v-else class="search-container-right" style="margin:2px 0 0 0">     
          <div class="export-button" style="margin-left:15px;margin-top:0">
            <img src="../../../assets/assessment/icon-export.png" alt="" />
            <span @click="clickAllExcel">批量打印第二次补考成绩单</span>
          </div>
        </div>
      </div>
    </div>
    <div class="plan-entry-table-container">
      <el-table
        :data="tableData"
        style="width: 100%"
        class="xpaas-table-class"
        row-class-name="xpaas-row-class"
        cell-class-name="xpaas-cell-class"
        header-row-class-name="xpaas-header-row-class"
        header-cell-class-name="xpaas-header-cell-class"
        @selection-change="handleSelection"
      >
        <el-table-column width="70" align="center" type="selection">
        </el-table-column>
        <el-table-column
          prop="dccjd"
          label="打印"
          width="134"
          align="center"
        >
          <template slot-scope="scope">
            <div class="lucj-expot-button">
              <img src="../../../assets/assessment/icon-export.png" alt="" />
              <span @click="downScore(scope.$index)">打印</span>
            </div>
            <div class="lucj-import-button" style="width:81px">
              <img src="../../../assets/assessment/icon-plan-record-detail.png" alt="" />
              <span @click="details(scope.row)">预览</span>
            </div>
          </template>
        </el-table-column> 
        <el-table-column prop="courseno" label="课程编号" align="center">
        </el-table-column>
        <el-table-column prop="coursename"  label="课程名称" align="center">         
        </el-table-column>
        <el-table-column prop="level" label="培养层次" align="center" v-if="type == 'one'">
        </el-table-column>
        <el-table-column prop="pylevel" label="培养层次" align="center" v-if="type == 'two'">
        </el-table-column>
        <el-table-column prop="bx" label="系" align="center" v-if="type == 'one'">
        </el-table-column>
        <el-table-column prop="professionaldivisions" label="教研室" align="center" v-if="type == 'one'">
        </el-table-column>
        <el-table-column prop="nj" label="年级" width="143" align="center" v-if="type == 'one'">
        </el-table-column>
        <el-table-column prop="professionaldivisions" label="专业班次" align="center" v-if="type == 'one'">
        </el-table-column>
        <el-table-column prop="department" label="系" align="center" v-if="type == 'two'">
        </el-table-column>
        <el-table-column prop="teachingandresearchsection" label="教研室" align="center" v-if="type == 'two'">
        </el-table-column>
        <el-table-column prop="nj" label="年级" width="143" align="center" v-if="type == 'two'">
        </el-table-column>
        <el-table-column prop="proclassname" label="专业班次" align="center" v-if="type == 'two'">
        </el-table-column>
        <el-table-column prop="yil" label="应录" width="84" align="center">
        </el-table-column>
        <el-table-column prop="yl" label="已录" width="84" align="center">
        </el-table-column>
        <el-table-column prop="wl" label="未录" width="84" align="center">
        </el-table-column>
      </el-table>
      <div class="block" style="margin-bottom: 50px">
        <el-pagination
          style="width:auto;margin-top: 15px;float:right;margin-bottom:50px;padding:0"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="cuurrentPage"
          :page-sizes="[5, 10, 20, 30,50,100,200]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.length > 0 ? tableData[0].tol : ''"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog
      title="导出分项成绩单"
      :visible.sync="showExportReportDialog"
      class="export-report-container"
      width="779px"
    >
      <div>
        <el-radio-group v-model="reportType">
          <el-radio
            :label="item.label"
            v-for="(item, index) in reportTypes"
            :key="index"
            class="large"
            >{{ item.value }}</el-radio
          >
        </el-radio-group>
      </div>
      <span slot="footer" class="dialog-footer">
        <button class="yellow" @click="showExportReportDialog = false">
          确 定
        </button>
      </span>
    </el-dialog>
    <el-dialog
      title="按模板导入课程成绩"
      :visible.sync="showInportReportDialog"
      class="import-report-container"
      width="983px"
    >
      <div>
        <span>请选择数据文件：</span>
        <input type="text" v-model="filepath" />
        <div @click="changeInputFile()">
          <span>浏览</span>
          <input
            type="file"
            id="theFile"
            name="theFile"
            onchange="document.getElementById('theFilePath').value=this.value"
          />
        </div>
        <div>下载数据模板文件</div>
      </div>
      <span slot="footer" class="dialog-footer">
        <button class="green" @click="showInportReportDialog = false">
          提交
        </button>
      </span>
    </el-dialog>
    <el-dialog
      title="查看"
      :visible.sync="showManualEntryDialogasc"
      width="1185px"
      class="manual-entry-containerass" 
    >
    <div class="my-form-container" style="width:100%;height:484px">
      <el-row>
        <el-col :span="16">
          <div>标准体系名称</div>
          <div>
            <el-input
              v-model="class_nameac1"
              style="width: 234px"
              placeholder="名称填写"
            ></el-input>
          </div>
        </el-col>
      </el-row>
        <el-row>
        <el-col :span="16">
          <div>所属上级指标项名称</div>
          <div>
            <el-input
              v-model="class_nameac2"
              style="width: 234px"
              placeholder="名称填写"
            ></el-input>
          </div>
        </el-col>
      </el-row>
        <el-row>
        <el-col :span="16">
          <div>指标项级别</div>
          <div>
            <el-input
              v-model="class_nameac3"
              style="width: 234px"
              placeholder="名称填写"
            ></el-input>
          </div>
        </el-col>
      
      </el-row>
        <el-row>
        <el-col :span="16">
          <div>指标项名称</div>
          <div>
            <el-input
              v-model="class_nameac4"
              style="width: 234px"
              placeholder="名称填写"
            ></el-input>
          </div>
        </el-col>
      
      </el-row>
        <el-row>
        <el-col :span="16">
          <div>指标项说明</div>
          <div>
            <el-input
              v-model="class_nameac5"
              style="width: 234px"
              placeholder="名称填写"
            ></el-input>
          </div>
        </el-col>
      
      </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <button @click="showManualEntryDialogasc = false">保存</button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { reqGetXqList,reqCheckLevelList } from "@/api/admin1/check";
import { getxb,getClass,queryXBclassroom,outBKallCJD,reqeditById } from "@/api/course/courses";
import { scoreBuAll,saveBukaoTwo } from "@/api/courseAchievement/scoreentry";
export default {
  data() {
    return {
      pageNo:1,
      pageSize:10,
      xq: '',
      onemorexueqi:'',
      xb:'',
      gClass:'',
      pycc:'', 
      coursename: '',
      eduLevel:'',
      xqList: [],
      xbList:[],
      gClassList:[],
      levelList:[],
      showManualEntryDialog: false,
      class_frequency: "A,B,C,D",
      class_frequencys: [{ label: "2", value: "2" }],
      class_name: "",
      design: '',
      showManualEntryDialogasc: false,
      class_nameac1: "",
      class_nameac2: "A,B,C,D",
      class_nameac3: "A",
      class_nameac4: "23",
      class_nameac5: "无",
      tableData: [],    
      showExportReportDialog: false,
      showInportReportDialog: false,
      reportType: "课下作业",
      reportTypes: [
        { label: "课下作业", value: "课下作业" },
        { label: "课下测评", value: "课下测评" },
        { label: "期中考试", value: "期中考试" },
        { label: "课终考核", value: "课终考核" },
      ],
      type:this.$route.query.type,
      handleSelectionData:[]
    };
  },
  mounted() {
    this.termAll();
    this.xbAll();
    this.classAll();
    this.getLevelList();
    this.clickSearch();
  },
  methods: {
    handleCurrentChange(val) {
      this.pageNo = val;
      this.clickSearch();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.clickSearch();
    },
    async termAll(){
      const result = await reqGetXqList();
      result.data.code == 200 ? this.xqList = result.data.data : [];
    },
    async xbAll(){
      const xb = await getxb();
      xb.data.code == 200 ? this.xbList = xb.data.data : [];
    },
    async classAll(){
      const gClass = await getClass();
      gClass.data.code == 200 ? this.gClassList = gClass.data.data : [];
    },
    // 获取培养层次下拉框
    async getLevelList() {
      const result = await reqCheckLevelList('pylevel');
      result.data.code == 200 ? this.levelList = result.data.data[0].children : [];
    },
    // 根据系部选中获取教研室
    async handleXb(val){
      if(val){
        const xbClass = await queryXBclassroom(val);
        xbClass.data.code == 200 ? this.gClassList = xbClass.data.data : [];
        this.gClass = ''
      } else {
        this.xbAll();
        this.classAll();
      }
    },
    // 教研室下拉框的改变
    handleClass(val){
      if(!val){
        this.xb ? this.handleXb(this.xb)  : this.classAll();
      }
    },
    searchClick(){
      this.pageNo = 1;
      this.clickSearch();
    },
    // 获取页面数据
    clickSearch() {
      let obj = {};
      this.tableData =[]
      if(this.type === 'one'){
        console.log(799898)
        obj = {
          bkxueqi: this.xq,
          departiment: this.xb,
          levelid: this.eduLevel,
          coursename: this.coursename,
          teachingfaculty: this.gClass,
          pageNo:this.pageNo,
          pageSize:this.pageSize
        };
        return new Promise(() => {
          scoreBuAll(obj).then((res) => {
            this.tableData = res.data.data;
          });
        });
      } else if(this.type === 'two'){
        console.log(12121)
        obj = {
          onemorexueqi: this.onemorexueqi,
          departiment: this.xb,
          levelid: this.eduLevel,
          coursename: this.coursename,
          teachingfaculty: this.gClass,
          pageNo:this.pageNo,
          pageSize:this.pageSize
        };
        return new Promise(() => {
          saveBukaoTwo(obj).then((res) => {
            this.tableData = res.data.data;
          });
        });
      }
    },
    toManualEntry() {
      this.$router.push("/teacher/courseAchievement/manualEntry");
    },
    toMakeupScoreEntry() {
      this.$router.push("/teacher/courseAchievement/entryResults");
    },
    //单列成绩点击打印
    downScore(index) {
      this.reportIndex = index;
      let planid1 = this.tableData[this.reportIndex].planid;
      outBKallCJD(planid1).then(res=>{
        if("success" === res.data.data.code) {
          const downloadURL = window.location.origin + `/api/xpaas-course-service/testscorequery/outBKallCJD?planids=${planid1}`;
          window.open(downloadURL, '_blank');
        } else {
          this.$message({ type: "error", message: res.data.data.msg });
        }
      })
    },
    //点击预览
    details(row){
      reqeditById(row.planid).then(res=>{
        let data = res.data.data;
        if(res.data.code == 200 && data.kxzystate == '3' && data.ktcpstate == '3' && data.qzksstate == '3' && data.kzkhstate == '3' && data.oldstate == '3' && data.oldstate2 == '3'){
          localStorage.setItem('studentData',JSON.stringify(data));
          localStorage.setItem('routetwoSign','examPage');
          this.$router.push({
            path: "/admin/courseAssessment/requditByInfo", //要跳转的页面的路由
          });
        } else {
          this.$message({ type: "error", message: '该课程的成绩还在审核中！' });
        }
      })
    },
    handleSelection(val){
      this.handleSelectionData = val;
    },
    //批量打印
    clickAllExcel(){
      if(this.handleSelectionData.length > 0){
        let planid = '';
        let newplanid = '';
        this.tableData.forEach(item=>{
          planid += item.planid + ',';
          newplanid = planid.substring(0,planid.length - 1);
        })
        outBKallCJD(newplanid).then(res=>{
          if("success" === res.data.data.code) {
            const downloadURL = window.location.origin + `/api/xpaas-course-service/testscorequery/outBKallCJD?planids=${newplanid}`;
            window.open(downloadURL, '_blank');
          } else {
            this.$message({ type: "error", message: res.data.data.msg });
          }
        })
      } else {
        this.$message({ type: "error", message: '请选择需要导出的数据！' });
        return
      }
    }
  },
};
</script>
<style lang="less" scoped>
.assessment-container {
  .export-report-container {
    .el-dialog__body {
      padding: 64px 0 64px 50px;
      .el-radio {
        margin-right: 79px;
      }
    }
    .el-dialog__footer {
      padding-bottom: 103px;
    }
  }
  .import-report-container {
    .el-dialog__body {
      padding-left: 165px;
      padding-top: 71px;
      padding-bottom: 60px;
      > div {
        > span {
          font-size: 18px;
          font-weight: bold;
          line-height: 20px;
          color: #004ca7;
          vertical-align: middle;
        }
        > input {
          width: 254px;
          height: 25px;
          border: 1px solid #004ca7;
          opacity: 1;
          border-radius: 4px;
          padding-left: 5px;
          margin-right: 8px;
          color: #004ca7;
          vertical-align: middle;
        }
        > div {
          display: inline-block;
          font-size: 18px;
          padding: 1px 10px;
          border-radius: 4px;
          vertical-align: middle;
          cursor: pointer;
          &:nth-child(3) {
            color: rgba(2, 200, 108, 1);
            background: #f1fff8;
            border: 1px solid #02c86c;
            position: relative;
            margin-right: 20px;
            > input {
              width: 0px;
              position: absolute;
              left: 0;
              opacity: 1;
              cursor: pointer;
            }
          }
          &:nth-child(4) {
            color: rgba(82, 48, 233, 1);
            background: rgba(235, 230, 255, 1);
            border: 1px solid rgba(82, 48, 233, 1);
          }
        }
      }
    }
    .el-dialog__footer {
      padding-bottom: 76px;
      .green {
        padding: 1px 17px;
      }
    }
  }
   .manual-entry-container {
    .el-dialog__body {
      height: 390px;
      > div {
        width: 1014px;
        border: 1px solid rgba(0, 76, 167, 0.8);
        border-radius: 6px;
        margin: 0 auto;
        > div {
          border-bottom: 1px solid rgba(0, 76, 167, 0.39);
          &:last-child {
            border-bottom: none;
          }
          > div {
            display: flex;
            > div {
              height: 96px;
              display: flex;
              align-items: center;
              justify-content: center;
              &:nth-child(1) {
                width: 420px;
                text-align: center;
                font-size: 16px;
                font-weight: bold;
                color: #004ca7;
                background: rgba(77, 129, 192, 0.1);
              }
              &:nth-child(2) {
                padding-left: 19px;
              }
            }
          }
        }
      }
    }
    .el-dialog__footer {
      padding-bottom: 43px;
    }
    .dialog-footer {
      > button {
        width: 87px;
        height: 36px;
        background: #fff6ef;
        border: 1px solid #f3b815;
        border-radius: 6px;
        background: rgba(255, 246, 239, 1);
        font-size: 18px;
        color: #f3b815;
      }
    }
  }
    .manual-entry-containerass {
    .el-dialog__body {
      height: 520px;
      > div {
        width: 1014px;
        border: 1px solid rgba(0, 76, 167, 0.8);
        border-radius: 6px;
        margin: 0 auto;
        > div {
          border-bottom: 1px solid rgba(0, 76, 167, 0.39);
          &:last-child {
            border-bottom: none;
          }
          > div {
            display: flex;
            > div {
              height: 96px;
              display: flex;
              align-items: center;
              justify-content: center;
              &:nth-child(1) {
                width: 420px;
                text-align: center;
                font-size: 16px;
                font-weight: bold;
                color: #004ca7;
                background: rgba(77, 129, 192, 0.1);
              }
              &:nth-child(2) {
                padding-left: 19px;
              }
            }
          }
        }
      }
    }
    .el-dialog__footer {
      padding-bottom: 43px;
    }
    .dialog-footer {
      > button {
        width: 87px;
        height: 36px;
        background: #fff6ef;
        border: 1px solid #f3b815;
        border-radius: 6px;
        background: rgba(255, 246, 239, 1);
        font-size: 18px;
        color: #f3b815;
      }
    }
  }
}
.plan-entry-table-container {
  margin-top: 15px;
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }
  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }
  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }
  .el-checkbox__inner:hover {
    border-color: #004ca7;
  }
  .el-checkbox__inner {
    border: 1px solid #004ca7;
    border-radius: 0;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #004ca7;
    border-color: #004ca7;
  }
  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #004ca7;
  }
  .el-checkbox.is-bordered.is-checked {
    border-color: #004ca7;
  }
  .el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #004ca7;
  }
  .export-button {
    background: #fff6ef;
    border: 1px solid #f3b815;
    width: auto;
    height: 28px;
    line-height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 3px 10px;
    box-sizing: border-box;
    > span {
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
    > img {
      width: 16px;
      height: 16px;
      margin-right: 5px;
    }
  }

  .lucj-import-button {
    .export-button;
    width: 116px;
    margin: 0 auto 12px;
    background: #f1fff8;
    border: 1px solid #02c86c;
    &:last-child {
      margin-bottom: 0px;
    }
    > span {
      color: #02c86c;
    }
  }
  .lucj-expot-button {
    .export-button;
    background: #fff6ef;
    border: 1px solid #f3b815;
    width: 81px;
    margin: 0 auto 10px;
    &:last-child {
      margin-bottom: 0px;
    }
    > span {
      color: #f3b815;
    }
  }
}
</style>

<style lang="less" scoped>
@import "../../../styles/print-entry.less";
.plan-entry-table-container {
  margin-top: 15px;
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}
@fontFamily:"Microsoft YaHei";
.xpaas-table-class {
  border: 1px solid #004ca7;
  border-radius: 9px;
  > ::v-deep div.el-table__header-wrapper {
    > table.el-table__header {
      > thead {
        > tr.xpaas-header-row-class {
          padding: 0;
          height: 76px;
          background-color: #edf2f9;
          font-size: 16px;
          font-family: Microsoft YaHei;
          font-weight: bold;
          line-height: 20px;
          color: #004ca7;
          > th.xpaas-header-cell-class {
            font-weight: bold;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            > div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
  > ::v-deep div.el-table__body-wrapper {
    > table.el-table__body {
      > tbody {
        > tr.xpaas-row-class {
          > td.xpaas-header-cell-class {
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            > div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
          > td.xpaas-cell-class {
            height: 76px;
            
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            > div.cell {
              font-weight: normal;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
}
</style>